<?php

namespace App\Modules\Apicrzs\Services\Water;

use App\Exceptions\Exception;
use App\Modules\Admin\Entities\Equipment\DeviceWarrantyModel;
use App\Modules\Apicrzs\Services\BaseServices;
use App\Traits\CryptAES;
use Illuminate\Support\Facades\DB;

class DeviceWarrantyService extends BaseServices
{
    public function __construct(DeviceWarrantyModel $model)
    {
        $token = \request()->header('token');
        $user_info = CryptAES::decryptToken($token, 'user_grzq');
        $this->user_id = $user_info['data']['user_id'] ?? "";
        $this->model = $model;
    }

    public function createWarranty($params)
    {
        $params['user_id'] = $this->user_id;
        DB::beginTransaction();
        try{
            $params['path_file'] = json_encode($params['path_file']);
            parent::create($params); // TODO: Change the autogenerated stub
            DB::commit();
            return true;
        }catch (Exception $e){
            DB::rollBack();
            throw new Exception($e->getMessage());
        }
    }
}
